package cm.tfd.hospital.util;

import android.app.Activity;
import android.text.TextUtils;

import cm.tfd.hospital.common.Common;
import cm.tfd.hospital.entity.UserBean;


/**
 * Created by yuye on 2018/5/24.
 */

public class UserUtils {
    private static UserBean.User mUser;

    public static void setUser(UserBean.User user) {
        mUser = user;
        if (user == null) {
            SpUtils.getInstance().remove(Common.SP_LOGIN_JSON, true);
        } else {
            SpUtils.getInstance().put(Common.SP_LOGIN_JSON, JsonUtils.toJson(user), true);
        }
    }

    public static UserBean.User getUser() {
        if (mUser == null) {
            String loginJson = SpUtils.getInstance().getString(Common.SP_LOGIN_JSON, "");
            if (!TextUtils.isEmpty(loginJson)) {
                mUser = JsonUtils.parseObject(loginJson, UserBean.User.class);
            }
        }
        return mUser;
    }

    public static boolean isLogin(Activity activity) {
        if (UserUtils.getUser() == null) {
//            activity.startActivity(new Intent(activity, LoginActivity.class));
            return false;
        } else {
            return true;
        }
    }
}
